package com.love.cloud.auth.service.impl;

import com.love.cloud.admin.api.dto.UserInfo;
import com.love.cloud.admin.api.provider.RemoteUserProvider;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * 用户详细信息
 *
 * @author hongdongqu
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class MyPhoneOpenCodeServiceImpl extends BaseUserDetailServiceImpl {
	@DubboReference(version = "1.0.0", timeout = 30000)
	private RemoteUserProvider remoteUserProvider;


	@Override
	protected UserInfo getUser(String phone) {
		try {
			UserInfo info = remoteUserProvider.infoByPhone(phone);
			if (info == null) {
				throw new UsernameNotFoundException("未查询到该用户");
			}
			return info;
		}catch (Exception e){
			throw new UsernameNotFoundException(e.getMessage());
		}
	}
}
